<?php
/****************多维数组转一维数组*************************/
function arrToOne($multi) {
    $arr = array();
    foreach ($multi as $key => $val) {
        if( is_array($val) ) {
            $arr = array_merge($arr, arrToOne($val));
        } else {
            $arr[] = $val;
        }
    }
    return $arr;
}
/****************跨域*************************/
function kuayu()
{
    header('content-type:application:json;charset=utf8');
    header('Access-Control-Allow-Origin:*');
    header('Access-Control-Allow-Methods:POST');
    header('Access-Control-Allow-Headers:x-requested-with,content-type');
}
/****************生成guid*************************/
function create_guid() {
    $charid = strtoupper(md5(uniqid(mt_rand(), true)));
    $hyphen = chr(45);// "-"
    $uuid =substr($charid, 0, 8).$hyphen
        .substr($charid, 8, 4).$hyphen
        .substr($charid,12, 4).$hyphen
        .substr($charid,16, 4).$hyphen
        .substr($charid,20,12);
//         chr(123)
//         ..chr(125);
    return $uuid;
}

/****************查用户的地址*************************/
function query_address($uid){
    $address = D('Users_address');
    $address_id = D('Users')->where('id='.$uid)->getfield('address_id');
    $info['default_address'] = $address->find($address_id);
    $info['address'] = $address->where('user_id='.$uid)->select();
    return $info;
}

/****************查指定购物车的商品*************************/
function quert_cart_good($cart_id,$uid){
    $sql = "select g.id,g.cn,g.product_name,g.img1,g.shop_price,c.number from wlg_cart as c right JOIN wlg_goods as g on c.good_id=g.id where c.uid=".$uid." and c.id in (".$cart_id.");";
//        $sql = "select g.id,g.cn,g.product_name,g.shop_price,c.number from wlg_cart as c right JOIN wlg_goods as g on c.good_id=g.id where c.uid=".$data['uid']." and c.id in (".$data['cart_id'].");";
    $goods = M()->query($sql);
    return $goods;
}


/**************为一个订单生生成支付宝支付按钮****************/
function makeAlipayBtn($orderId,$btnName = "去支付宝支付")
{
    //return require('./alipay/alipayapi.php');
    return require('./Public/interface/alipay/alipayapi.php');
}


// function checkorderstatus($ordid){
//     $Ord=M('Orderlist');
//     $ordstatus=$Ord->where('ordid='.$ordid)->getField('ordstatus');
//     if($ordstatus==1){
//         return ture;
//     }else{
//         return false;
//     }
//  }

// //处理订单函数
// // 更新订单状态，写入订单支付后返回的数据
//  function orderhandle($parameter){
//     $ordid=$parameter['out_trade_no'];
//     $data['payment_trade_no']       =$parameter['trade_no'];
//     $data['payment_trade_status']   =$parameter['trade_status'];
//     $data['payment_notify_id']      =$parameter['notify_id'];
//     $data['payment_notify_time']    =$parameter['notify_time'];
//     $data['payment_buyer_email']    =$parameter['buyer_email'];
//     $data['ordstatus']              =1;
//     $Ord = M('Orderlist');
//     $Ord->where('ordid='.$ordid)->save($data);  
//  }
// //获取一个随机且唯一的订单号
//  function getordcode(){
//     $Ord = M('Orderlist');
//     $numbers = range(10,99);
//     shuffle($numbers);
//     $code = array_slice($numbers,0,4);
//     $ordcode = $code[0].$code[1].$code[2].$code[3];
//     $oldcode = $Ord->where("ordcode='".$ordcode."'")->getField('ordcode');
//     if($oldcode){
//         getordcode();
//     }else{
//         return $ordcode;
//     }
//  }


?>  